<template>
	<view class="page home bgf7 c85">
		<image class="w-20 bg" src="/static/img/bg/home_bg.png"></image>
		<view class="aliC cff title pb16 rel" :style="{paddingTop: statusBar + 'px'}">助教</view>
		
		<scroll-view scroll-y="true" :style="{height: 'calc(100vh - 214rpx - ' + statusBar +'px)'}">
			<view class="bgff mx15 rel r7 pt16 pb24 mt18 shadow">
				<u-tabs lineColor="#F5C51D" :list="list" lineWidth="42" lineHeight="4" @click="switchTab"
					:itemStyle="{width: 'calc(33% - 22px)',paddingBottom: '5px'}"></u-tabs>

				<view class="flex flexC flexB aliC px26 mt10">
					<view @click="showTotal">
						<view class="bold6 fs17 c00">{{total}}</view>
						<view class="c85 mt2">总流水(元)</view>
					</view>
					<view>
						<view class="bold6 fs17 c00">{{order}}</view>
						<view class="c85 mt2">订单数</view>
					</view>
					<view>
						<view class="bold6 fs17 c00">{{wait}}</view>
						<view class="c85 mt2">待接单</view>
					</view>

				</view>

			</view>
			<swiper autoplay circular class="bgImg my8 ml15 mr15">
				<swiper-item :key="index">
					<image src="/static/img/bg/banner1.jpg" class="w-20" mode="widthFix"></image>
				</swiper-item>
				<swiper-item :key="index">
					<image src="/static/img/bg/banner2.jpg" class="w-20" mode="widthFix"></image>
				</swiper-item>
			</swiper>
			<view class="bgff r7 mx15 my12  pb24 fs13 aliC flex flexC flexW shadow">


				<view class="w-4 pt18" @click="goDetail">
					<image class="w36" src="/static/img/icon/chongzhi.png" mode="aspectFill"></image>
					<view class="mt4">资料修改</view>
				</view>
				<view class="w-4 pt18" @click="goSet">
					<image class="w36" src="/static/img/icon/room.png" mode="aspectFill"></image>
					<view class="mt4">接单设置</view>
				</view>

			<!-- 	<view class="w-4 pt18" @click="goTuan()">
					<image class="w36" src="/static/img/icon/tuan_icon.png" mode="aspectFill"></image>
					<view class="mt4">收益明细</view>
				</view -->

	
			
			</view>

		
		</scroll-view>


		<!-- 店铺选择 -->
		<uni-popup ref="shopPicker" type="bottom">
			<shop-list @search="search" :list="shopList" @onSelectShop="onSelectShop" @close="onClose"></shop-list>
		</uni-popup>
		<tabbar></tabbar>
	</view>
</template>

<script>
	const statusBar = uni.getSystemInfoSync().statusBarHeight + 10;
	export default {
		data() {
			return {
				statusBar,
				list: [{
						name: '今天'
					},
					{
						name: '昨天'
					},
					{
						name: '本月'
					}
				],
				total:0,
				order:0,
				wait:0
			


			}
		},
		onLoad() {
		},
		onShow() {
			this.getIndex();
		},
		methods: {

			goDetail(){
				uni.navigateTo({
					url: '/other/job/detail'
				})
			},

			goOpen(type) {
				let param = {
					shop_id: this.selectShop.id,
					door: type
				};
				let that = this;
				this.$api.openNewDoor(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						if (res.data == 2) {
							that.$refs.pop.open();
						}
					} else {

					}
				})

			},

			goSet() {
				uni.navigateTo({
					url: '/other/job/set'
				})
			},

			goTuan() {
				uni.navigateTo({
					url: '/other/coupon/couponList?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goTuanBuy() {
				uni.navigateTo({
					url: '/other/coupon/couponBuyList?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goPackage() {
				uni.navigateTo({
					url: '../package/index?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goDevice() {
				uni.navigateTo({
					url: '/other/device/device'
				})
			},

			goClean() {
				uni.navigateTo({
					url: '/other/staff/index?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goCharge() {
				uni.navigateTo({
					url: '/other/recharge/list?selectShop=' + JSON.stringify(this.selectShop)

				})
			},

			shj() {
				uni.navigateToMiniProgram({
					appId: 'wx3c9509c6a53b4489',
					path: 'pages/index/index', // 不填默认首页
					extraData: {
						'data1': 'test'
					},
					success(res) {
						// 打开成功
					}
				})


			},

			wifi() {
				uni.navigateTo({
					url: '/other/device/wifi?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goRoom() {
				uni.navigateTo({
					url: '../room/index?selectShop=' + JSON.stringify(this.selectShop)
				})
			},
			goStaff() {
				uni.navigateTo({
					url: '/other/staff/staff?selectShop=' + JSON.stringify(this.selectShop)
				})
			},

			goScan() {
				uni.scanCode({
					complete: function(res) {

					}
				})
			},
			goShop() {
				uni.navigateTo({
					url: '/other/shop/list'
				})
			},



			switchTab(e) {
				var name = e.name;
				if (name == '今天') {
					this.currentIndex = 1;
				} else if (name == '昨天') {
					this.currentIndex = 2;
				} else {
					this.currentIndex = 3;
				}
				this.getIndex();
				console.info(JSON.stringify(e));
			},

			showShop() {
				this.$refs.shopPicker.open();

			},
			search(value) {

				this.keyword = value;
				this.getShopList();
			},

			onSelectShop(item) {
				this.selectShop = item;
				uni.setStorageSync("selectShop", JSON.stringify(this.selectShop))
				this.$refs.shopPicker.close();
				this.getIndex();
				this.getShopIndexDevice();

			},

			getIndex() {
				let param = {
					date: this.currentIndex
				};
				let that = this;
				this.$api.assistantIndex(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {

						that.total = res.data.total;
						that.order = res.data.order;
						that.wait = res.data.wait;
					

					} else {

					}
				})
			},

			getShopIndexDevice() {
				let param = {
					shop_id: this.selectShop.id,
				};
				let that = this;
				this.$api.getShopIndexDevice(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {

						that.deviceTotal = res.data.total;
						that.deviceOnline = res.data.online;
						that.deviceOffline = res.data.offline;


					} else {

					}
				})
			},


			getShopList() {
				let param = {
					keyword: this.keyword
				};
				let that = this;
				this.$api.getShopList(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.shopList = res.data;
						if (that.shopList.length > 0) {
							that.selectShop = that.shopList[0];
							uni.setStorageSync("selectShop", JSON.stringify(that.selectShop))
							that.getIndex();
							that.getShopIndexDevice();

						}
					} else {

					}
				})
			},

			onClose() {
				this.$refs.shopPicker.close();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		.down {
			width: 36rpx;
			height: 36rpx;
		}

		.bg {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 0;
		}

		.rel {
			position: relative;
		}

		.right {
			width: 14rpx;
		}

		.w36 {
			width: 72rpx;
			height: 72rpx;
		}
	}

	.popup-content2 {
		background: #FFFFFF;

		.popup-btn {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
		}

		.button {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
			font-size: 11pt;
		}

		button::after {
			border: none;
		}

		.pt20 {
			border-bottom: 20rpx solid #f5f5f5;
		}
	}
</style>